package cn.iocoder.yudao.module.system.dal.mysql.examtest;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.system.controller.admin.examtest.vo.ExamTestPageReqVO;
import cn.iocoder.yudao.module.system.dal.dataobject.examtest.ExamTestDO;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

/**
 * 考试信息 Mapper
 *
 * @author 芋道源码
 */
@Mapper
public interface ExamTestMapper extends BaseMapperX<ExamTestDO> {

    default PageResult<ExamTestDO> selectPage(ExamTestPageReqVO reqVO) {
        LambdaQueryWrapperX<ExamTestDO> wrapper = new LambdaQueryWrapperX<ExamTestDO>()
                .likeIfPresent(ExamTestDO::getExamName, reqVO.getExamName())
                .eqIfPresent(ExamTestDO::getExamType, reqVO.getExamType())
                .eqIfPresent(ExamTestDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(ExamTestDO::getExamDate, reqVO.getExamDate())
                .betweenIfPresent(ExamTestDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ExamTestDO::getId);
        wrapper.apply(reqVO.getClassId() != null, "JSON_CONTAINS(class_ids, {0})", String.valueOf(reqVO.getClassId()));
        return selectPage(reqVO, wrapper);
    }

    default List<ExamTestDO> selectList(ExamTestPageReqVO reqVO) {
        LambdaQueryWrapperX<ExamTestDO> wrapper = new LambdaQueryWrapperX<ExamTestDO>()
                .likeIfPresent(ExamTestDO::getExamName, reqVO.getExamName())
                .eqIfPresent(ExamTestDO::getExamType, reqVO.getExamType())
                .eqIfPresent(ExamTestDO::getStatus, reqVO.getStatus())
                .betweenIfPresent(ExamTestDO::getExamDate, reqVO.getExamDate())
                .betweenIfPresent(ExamTestDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(ExamTestDO::getId);
        wrapper.apply(reqVO.getClassId() != null, "JSON_CONTAINS(class_ids, {0})", String.valueOf(reqVO.getClassId()));
        return selectList(wrapper);
    }

    default List<ExamTestDO> selectListByClassId(Long classId) {
        LambdaQueryWrapperX<ExamTestDO> wrapper = new LambdaQueryWrapperX<>();
        wrapper.apply("JSON_CONTAINS(class_ids, {0})", String.valueOf(classId));
        return selectList(wrapper);
    }



    default List<ExamTestDO> selectListByStatus(Integer status) {
        return selectList(ExamTestDO::getStatus, status);
    }

    default List<ExamTestDO> selectListByExamType(String examType) {
        return selectList(ExamTestDO::getExamType, examType);
    }

}